import React, { useContext, useEffect } from "react";
import useChatHistory from "./useChatHistory";
import { ChatContext } from "@/pages/BigScreen/context/store";

export interface IChatHistoryBoxProps {
  visible: boolean;
  handlePopupVisible: (visible: boolean) => void;
}
function useChatHistoryBox(props: IChatHistoryBoxProps) {
  const { visible } = props;
  const {
    isLoading,
    talkLists,
    selectTalk,
    talkFilterLists,
    dialogVisible,
    currentTask,
    searchGroup,
    onRefreshSession,
    onHandleChangeTalk,
    setSearchGroup,
    updateSession,
    setDialogVisible,
    setCurrentTask,
    editTask,
  } = useChatHistory();
  const { changeSession } = useContext(ChatContext);

  useEffect(() => {
    if (visible) {
      onRefreshSession();
    }
  }, [visible]);

  return {
    talkLists,
    selectTalk,
    talkFilterLists,
    dialogVisible,
    currentTask,
    searchGroup,
    isLoading,
    onRefreshSession,
    onHandleChangeTalk,
    setSearchGroup,
    updateSession,
    setDialogVisible,
    setCurrentTask,
    editTask,
    changeSession,
  };
}

export default useChatHistoryBox;
